﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class StemmingTestPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected void Submit_Click(object sender, EventArgs e)
    {
        String inputText = this.urlTextBox.Text;
        string[] stemWords;
        if (inputText == null || inputText.Equals(""))
        {
            this.output.InnerText = "No Output Input is Empty";
            stemWords = new String[0];
        }
        else
        {
            inputText = RemoveSpecialCharacters(inputText);
            stemWords = inputText.Split(' ');
            ZachmanServiceReference.Assignment3ServiceClient client = new ZachmanServiceReference.Assignment3ServiceClient();

            string[] words = client.Stemming(stemWords);
            if (words != null && words.Length != 0)
            {
                string finalWords = "";
                foreach (string word in words)
                {
                    finalWords += word;
                    finalWords += ", ";
                }
                this.output.InnerText = finalWords;
            }
            else
            {
                this.output.InnerText = "No Output :-(";
            }
        }
    }

    public static string RemoveSpecialCharacters(string str)
    {
        String sb = "";
        foreach (char c in str)
        {
            if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '.' || c == '_' || c == ' ')
            {
                sb += c;
            }
        }
        return sb.ToString();
    }
}